package com.jy.wms.service;

import com.github.pagehelper.Page;

import com.github.pagehelper.PageHelper;
import com.jy.wms.common.PinyinUtils;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.dao.ProvincialDynamicReportsMapper;
import com.jy.wms.pojo.WmsFreightStatisticsInVariousProvinces;
import com.jy.wms.pojo.WmsHead;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
public class WmsReportHeaderService extends BaseService<ProvincialDynamicReportsMapper, WmsFreightStatisticsInVariousProvinces> {

    /**
     * 运费表头
     * @param
     * @return list
     */
    public JSONObject WmsFreightHead(Map<String,Object> mapp,String hzid,String ckid) {
        JSONObject json=new JSONObject();
        PinyinUtils pinyin=new PinyinUtils();
        //单独查询出省
        String state = (String) mapp.get("state");
        List<WmsHead> Sales=dao.WmsFreightHead(hzid,ckid);
        int page = (int) mapp.get("page");
        int rows = (int) mapp.get("rows");
        PageHelper.startPage(page, rows);

        Page<Map<String,Object>>map1= new Page<>();
        Map map=new LinkedHashMap<>();
        map.put("search","false");
        map.put("minWidth","0px");
        map.put("cRemarks","");
        map.put("prop","Province");
        map.put("label","省份");
        map1.add(map);
        Map pp=new LinkedHashMap<>();
        pp.put("search","false");
        pp.put("minWidth","0px");
        pp.put("cRemarks","");
        pp.put("prop","FreightCollection");
        pp.put("label","运费汇总");
        for (WmsHead user : Sales) {
            String ty=pinyin.ToPinyin(user.getMc());
            Map map2=new LinkedHashMap<>();
            map2.put("search","false");
            map2.put("minWidth","0px");
            map2.put("cRemarks","");
            map2.put("prop",ty);
            map2.put("label",user.getMc());
            map1.add(map2);
        }
        map1.add(pp);
        json.put("表头",map1);
        JSONArray array = JSONArray.fromObject(map1);
        json = SetStatus.setSearchType(array.toString(), (int) map1.getTotal());
        return json;
    }

    /**
     * 支数表头
     * @param
     * @return list
     */
    public JSONObject supportnumberhead(Map<String,Object> mapp,String hzid,String ckid) {
        JSONObject json=new JSONObject();
        PinyinUtils pinyin=new PinyinUtils();
        //单独查询出省
        String state = (String) mapp.get("state");
        List<WmsHead> Sales=dao.supportnumberhead(state,hzid,ckid);
        int page = (int) mapp.get("page");
        int rows = (int) mapp.get("rows");
        PageHelper.startPage(page, rows);
        Page<Map<String,Object>>map1= new Page<>();
        Map map=new LinkedHashMap<>();
        map.put("search","false");
        map.put("minWidth","0px");
        map.put("cRemarks","");
        map.put("prop","Province");
        map.put("label","省份");
        map1.add(map);
        Map pp=new LinkedHashMap<>();
        pp.put("search","false");
        pp.put("minWidth","0px");
        pp.put("cRemarks","");
        pp.put("prop","SupportNumberSummary");
        pp.put("label","支数汇总");
        for (WmsHead user : Sales) {
            Map map2=new LinkedHashMap<>();
            String ty=pinyin.ToPinyin(user.getMc());
            map2.put("search","false");
            map2.put("minWidth","0px");
            map2.put("cRemarks","");
            map2.put("prop",ty);
            map2.put("label",user.getMc());
            map1.add(map2);
        }
        map1.add(pp);
        json.put("表头",map1);
        JSONArray array = JSONArray.fromObject(map1);
        json = SetStatus.setSearchType(array.toString(), (int) map1.getTotal());
        return json;
    }

    /**
     * 销售额表头
     * @param
     * @return list
     */
    public JSONObject Saleshead(String state,String hzid,String ckid) {
        JSONObject json=new JSONObject();
        PinyinUtils pinyin=new PinyinUtils();
        //单独查询出省
        //String state = (String) mapp.get("state");
        List<WmsHead> Sales=dao.Saleshead(state,hzid,ckid);
        /*int page = (int) mapp.get("page");
        int rows = (int) mapp.get("rows");
        PageHelper.startPage(page, rows);*/
        Page<Map<String,Object>>map1= new Page<>();
        Map map=new LinkedHashMap<>();
        map.put("search","false");
        map.put("minWidth","0px");
        map.put("cRemarks","");
        map.put("prop","Province");
        map.put("label","省份");
        map1.add(map);
        Map pp=new LinkedHashMap<>();
        pp.put("search","false");
        pp.put("minWidth","0px");
        pp.put("cRemarks","");
        pp.put("prop","SalesVolumeSummary");
        pp.put("label","销售额汇总");
        for (WmsHead user : Sales) {
            String ty=pinyin.ToPinyin(user.getMc());
            Map map2=new LinkedHashMap<>();
            map2.put("search","false");
            map2.put("minWidth","0px");
            map2.put("cRemarks","");
            map2.put("prop",ty);
            map2.put("label",user.getMc());
            map1.add(map2);
        }
        map1.add(pp);
        json.put("表头",map1);
        JSONArray array = JSONArray.fromObject(map1);
        json = SetStatus.setSearchType(array.toString(), (int) map1.getTotal());
        return json;
    }

    /**
     * 订单量表头
     * @param
     * @return list
     */
    public JSONObject Orderquantityheader(String state,String hzid, String ckid) {
        JSONObject json=new JSONObject();
        PinyinUtils pinyin=new PinyinUtils();
        //单独查询出省
       // String state = (String) mapp.get("state");
        List<WmsHead> Sales=dao.Orderquantityheader(state,hzid,ckid);
        /*int page = (int) mapp.get("page");
        int rows = (int) mapp.get("rows");
        PageHelper.startPage(page, rows);*/
        Page<Map<String,Object>> map1= new Page<>();

        Map map=new LinkedHashMap<>();
        map.put("search","false");
        map.put("minWidth","0px");
        map.put("cRemarks","");
        map.put("prop","Province");
        map.put("label","省份");
        map1.add(map);
        Map pp=new LinkedHashMap<>();
        pp.put("search","false");
        pp.put("minWidth","0px");
        pp.put("cRemarks","");
        pp.put("prop","OrderQuantitySummary");
        pp.put("label","订单量汇总");
        for (WmsHead user : Sales) {
            String ty=pinyin.ToPinyin(user.getMc());
            Map map2=new LinkedHashMap<>();
            map2.put("search","false");
            map2.put("minWidth","0px");
            map2.put("cRemarks","");
            map2.put("prop",ty);
            map2.put("label",user.getMc());
            map1.add(map2);
        }
        map1.add(pp);
        json.put("表头",map1);
        JSONArray array = JSONArray.fromObject(map1);
        json = SetStatus.setSearchType(array.toString(), (int) map1.getTotal());
        return json;
    }
}
